package client.view;

import client.service.ChatService;
import client.service.ClientService;
import client.utility.Utility;
import common.User;
import jdk.jshell.execution.Util;

public class ClientView {
    private boolean exit=true;
    private String select="";

    private User user;
    private ClientService clientService=new ClientService();
    private ChatService chatService=new ChatService();

    public void loginView(){
        while(exit){
            System.out.println("\t欢迎来到盗版QQ");
            System.out.println("1.登录");
            System.out.println("0.退出");

            System.out.print("请输入你的选择:");
            select= Utility.readString(1);

            switch (select){
                case "1":
                    login();
                    break;
                case "0":
                    System.out.println("退出");
                    exit=false;
                    break;
            }
        }
    }
    private void login(){
        System.out.print("请输入账号:");
        String account=Utility.readString(10);
        System.out.print("请输入密码:");
        String password=Utility.readString(20);

        if(clientService.loginVerification(account,password)){
            System.out.println("登录成功");
            user=clientService.setUserToView();
            loginInView();
        }else {
            System.out.println("登录失败");
        }
    }
    private void loginInView(){
        System.out.println("\t\t欢迎"+user.getUser_name()+"登录QQ");
        while(exit) {
            System.out.println("===========盗版QQ (用户："+user.getUser_account() +"--"+ user.getUser_name()+  ")===========");
            System.out.println("\t\t 1.显示在线用户列表");
            System.out.println("\t\t 2.群聊");
            System.out.println("\t\t 3.私聊");
            System.out.println("\t\t 4.发送文件");
            System.out.println("\t\t 5.群发文件");
            System.out.println("\t\t 0.退出");

            System.out.print("请输入你的选择:");
            select=Utility.readString(1);
            switch (select){
                case "1":
                    clientService.requestOnlineFriend();
                    break;
                case "2":
                    System.out.print("请输入群聊名：");
                    String groupName=Utility.readString(50);
                    System.out.print("请输入群聊内容(限制100字)：");
                    String groupContent= Utility.readString(100);
                    chatService.groupChat(groupName,user.getUser_name(),groupContent);
                    break;
                case "3":
                    //连续不断的私聊或者群聊待完成……………………………………………………………………
                    System.out.print("请输入私聊对象(在线)：");
                    String getter=Utility.readString(50);
                    System.out.print("请输入私聊内容(限制100字)：");
                    String privateContent= Utility.readString(100);
                    chatService.privateChat(getter,user.getUser_name(),privateContent);
                    break;
                case "4":
                    System.out.print("请输入发送对象(在线):");
                    String fileToWho=Utility.readString(50);
                    System.out.print("请输入要发送的文件(完整路径):");
                    String fileName=Utility.readString(100);
                    chatService.sendFilePrivately(fileToWho,user.getUser_name(),fileName);
                    break;
                case "5":
                    System.out.print("请输入群聊名：");
                    String fileToGroup=Utility.readString(50);
                    System.out.print("请输入要发送的文件(完整路径):");
                    String file_name=Utility.readString(100);
                    chatService.sendFileToGroup(fileToGroup,user.getUser_name(),file_name);
                    break;
                case "0":
                    clientService.loginOut();
                    System.out.println(user.getUser_name()+" 退出");
                    exit=false;
                    break;
            }
        }
    }


}
